package com.example.mapper;

import com.example.model.DriverInfo;
import com.example.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by ykbboom on 2017/3/3.
 */
@Mapper
@Component
public interface UserMapper {
    @Select(value = { "select * from user where user_phone = #{userPhone}" })
    @ResultMap("com.example.mapper.UserMapper.UserResult")
    User getUserInfoByUserPhone(String userPhone);

    @Select(value = { "select user_name from user where user_id = #{userId}" })
    String getUserNameByUserId(int userId);

    @Select(value = { "select user_phone from user where user_id = #{userId}" })
    String getUserPhoneByUserId(int userId);
    @Insert(value = "insert into user(user_name,user_pass,user_phone) values(#{userName},#{userPass},#{userPhone})")
     void addUser(User user);

    @Select(value = { "select user_id from user where user_phone = #{userPhone}" })
    Integer checkUserExists(String userPhone);

    @Select(value = { "select user_id from user where user_phone = #{userPhone}" })
    Integer getUserIdByUserPhone(String userPhone);

    @Select(value = {"select user_name,user_phone from user where user_id = #{userId}"})
    @Results({
            @Result(column = "user_name", property = "driverName"),
            @Result(column = "user_phone", property = "driverPhone")
    })
    DriverInfo getDriverInfo(int userId);

    @Select(value = {"select user_id from request where request_id = #{requestId} "})
    Integer getCustomerIdByRequestId(int requestId);

    @Update(value = {"update user set user_point = #{userPoint} where user_id = #{userId}"})
    Integer updateDriverPoint(@Param("userPoint") int userPoint,@Param("userId") int userId);

    @Select(value = {"select user_point from user where user_id = #{userId} "})
    Integer getUserPointByUserId(int userId);

    @Select(value = {"select user_point from user where user_phone = #{userPhone} "})
    Integer getUserPointByUserPhone(String userPhone);

    @Update(value = {"update user set user_pass = #{newPass} where user_phone = #{userPhone}"})
    Integer updateUserPassword(@Param("newPass") String newPass,@Param("userPhone") String userPhone);
}
